//
//  CCVSExtendedLabel.m
//  ClinicalCollections
//
//  Created by Pasirstein, David B on 4/15/13.
//  Copyright (c) 2013 GOPI. All rights reserved.
//

#import "CCVSExtendedLabel.h"
#import "CCVSHyperLink.h"
#import "CCVSCommon.h"

@interface CCVSExtendedLabel ()

@property (nonatomic,weak) UIViewController * vc;

@end

@implementation CCVSExtendedLabel

@synthesize destination = _destination;
@synthesize title = _title;
@synthesize data = _data;
@synthesize vc = _vc;

//when a destination is set, we default the
//text color of the label...
-(void)setDestination:(NSURL *)destination
{
    [self setDefaults];
    _destination = destination;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

//set the default text color
-(void)setDefaults
{
    self.textColor = [UIColor blueColor];
}



-(BOOL)isExpandable //will return if the view should support dyanamic resizing
{
    return NO;
}

//should return the frame size with width and height populated
+(CGSize)calcViewHeight:(CGFloat)viewWidth fromObject:(id<CCVSCustomDataType>)data
{
    CGSize size = CGSizeMake(0, 0);
    NSString *text = ((CCVSHyperLink*)data).text;
    size = [text sizeWithFont:[UIFont fontWithName:@CCVS_FONTNAME size:CCVS_FONTSIZE]
            constrainedToSize:CGSizeMake(viewWidth, 9999)
                lineBreakMode:NSLineBreakByWordWrapping];
    return size;
}

//initialize the object...primary way it will be init'ed
-(id)initWithData:(id<CCVSCustomDataType>)data withFrame:(CGRect)frame viewController:(UIViewController*)vc
{
    self = [super initWithFrame:frame];
    //
    self.data = data;
    self.vc = vc;
    
    return self;
}

//should build view to be displayed (would likely return self)
-(UIView*)buildView
{
    self.userInteractionEnabled = YES;
    self.backgroundColor = [UIColor clearColor];
    self.numberOfLines = 0;
    self.lineBreakMode = NSLineBreakByWordWrapping;
    self.font = [UIFont fontWithName:@CCVS_FONTNAME size:CCVS_FONTSIZE];
    ///
    self.destination = ((CCVSHyperLink*)self.data).destinationURL;
    self.text = ((CCVSHyperLink*)self.data).text;
    ///
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self.vc action:@selector(handleTapGestureForURLViewType:)];
    tap.numberOfTapsRequired = 1;
    [self addGestureRecognizer:tap];
    ///
    return self;
}

-(BOOL)willSegueOnEvent //true/false if the view will require a segue
{
    return YES;
}

-(NSString*)nameOfSegue:(UIGestureRecognizer*)gesture
{
    return @WEBVIEW_SEGUE;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
